#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/ether.h>
#include <arpa/inet.h>
#include <unistd.h>

int main(int argc, char const *argv[])
{
    int sockfd;
    //创建链路层原始套接字
    if((sockfd = socket(AF_PACKET,SOCK_RAW,htons(ETH_P_ALL))) == -1)
    {
        perror("fail to socket");
        exit(-1);
    }
    printf("sockfd = %d\n",sockfd);

    //关闭原始套接字
    close(sockfd);
    return 0;
}
